package com.dianqiu.common.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.dianqiu.base.dao.impl.BaseDao;
import com.dianqiu.common.bean.DqBetUserMatchTO;
import com.dianqiu.common.dao.DqBetUserMatchDao;

@Component("dqBetUserMatchDao")
public class DqBetUserMatchDaoImpl extends BaseDao implements DqBetUserMatchDao{

	public void saveDqBetUserMatchTO(DqBetUserMatchTO betUserMatch) {
		this.getHibernateTemplate().save(betUserMatch);
	}

	public DqBetUserMatchTO getDqBetUserMatchByUserIdAndHandicapIdAndMatchId(
			String userId, Integer matchId, Integer handicapId) {
		DqBetUserMatchTO dqBetUserMatchTO = null;
		List<DqBetUserMatchTO> betUserMatchList = this.getHibernateTemplate().find(" from DqBetUserMatchTO betUserMatch " +
																				   " left outer join fetch betUserMatch.id betUserMatchId " +
																				   " left outer join fetch betUserMatch.dqMatch match " +
																				   " left outer join fetch match.dqClubsByHomeClbId homeClb " +
																				   " left outer join fetch match.dqClubsByAwayClbId awayClb " +
																				   " where betUserMatchId.userId = " + userId + 
																				   " and betUserMatchId.mthId = " + matchId + 
																				   " and betUserMatchId.hndpId = " + handicapId );
		if(betUserMatchList!=null && betUserMatchList.size()>0){
			dqBetUserMatchTO = betUserMatchList.get(0);
		}
		return dqBetUserMatchTO;
	}
	
	public List<DqBetUserMatchTO> getDqBetUserMatchListByUserIdAndHandicapIdAndMatchId(
			String userId, Integer matchId, Integer handicapId) {
		List<DqBetUserMatchTO> betUserMatchList = this.getHibernateTemplate().find(" from DqBetUserMatchTO betUserMatch " +
																				   " left outer join fetch betUserMatch.id betUserMatchId " +
																				   " left outer join fetch betUserMatch.dqMatch match " +
																				   " left outer join fetch match.dqClubsByHomeClbId homeClb " +
																				   " left outer join fetch match.dqClubsByAwayClbId awayClb " +
																				   " where betUserMatchId.userId = " + userId + 
																				   " and betUserMatchId.mthId = " + matchId + 
																				   " and betUserMatchId.hndpId = " + handicapId );
		
		return betUserMatchList;
	}
}
